<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <input id="upload" type="file" />
    <img id="preview" src="" alt="预览" />
    <script>
      const upload = document.querySelector("#upload");
      const preview = document.querySelector("#preview");

      upload.onchange = function() {
        const file = upload.files[0]; //File对象
        console.log('file', file);
        const src = URL.createObjectURL(file);
        console.log(src);
        preview.src = src;
      };
    </script>
  </body>
</html>
